using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Fieldbook.Entities;
using Fieldbook.Business;

namespace Fieldbook.Testwebsite.Admin
{
    public partial class SpeciesList : FieldbookPage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            ReddirectNonActiveSession();
            if (ddlPlantSpecieCategory.Items.Count == 0)
            {
                foreach (PlantSpecie.PlantCategory value in PlantSpecie.PlantCategory.GetValues(typeof(PlantSpecie.PlantCategory)))
                {
                    ddlPlantSpecieCategory .Items.Add(
                        new ListItem(value.ToString(),
                            ((byte)value).ToString()));
                }
            }
        }

        /// <summary>
        /// Add new field specie
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void linkAddSpecie_Command(object sender, CommandEventArgs e)
        {
            PlantSpecie specie = new PlantSpecie();
            specie.CategoryID = (PlantSpecie.PlantCategory)Int32.Parse(this.ddlPlantSpecieCategory.SelectedValue);
            specie.Description = this.txtDescription.Text;
            bool sucess = PlantSpecieController.InsertPlantSpecie(specie);

            if (sucess)
            {
                this.lblOperationStatus.Text = "Adding plant specie sucesfful";
                this.txtDescription.Text = "";
                this.dgvSpecies.DataBind();
            }
            else
            {
                this.lblOperationStatus.Text = "Error adding plant specie";
            }
        }
    }
}
